package com.company.bs2023;

/**
 * TODO
 *
 * @author jianf
 * @date 2024年03月29 9:10
 */
public class Putao {

    public static void main(String[] args) {
        long start = System.currentTimeMillis();
        int i = Putao.calcMinSpeed(13, 15, new int[]{23, 4, 24, 11, 12, 41, 33, 24, 4, 38, 12, 45, 20});
        System.out.println(i);
        long end = System.currentTimeMillis();
        System.out.println(start);
        System.out.println(end);
    }

    public static int calcMinSpeed(int n, int h, int[] s) {
        int max = 0;
        int k = 0;
        int temph = 0;
        //计算葡萄的总数
        for (int i = 0; i < n; i++) {
            max += s[i];
        }

        if (max % h == 0) {
            k = max / h;
        } else {
            k = max / h + 1;
        }

        for (int i = 0; i < n; i++) {
            if (temph >= h) {
                temph = 0;
                k++;
                i = -1;
                continue;
            }
            if (s[i] <= k) {
                temph += 1;
            } else if (s[i] % k == 0) {
                temph += s[i] / k;
            } else {
                temph += s[i] / k + 1;
            }
        }
        return k;

    }
}
